package com.Adapter;

import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bolao.R;
import com.entidades.Group;
import com.entidades.Team;

public class GroupListAdapter extends BaseAdapter {


	private static final int EXTRA = -1;
	private Group group;
	private LayoutInflater mInflater;
	private Context mContext;
	
	static class ViewHolder{
		private TextView teamName;
		private ImageView teamFlag;
		private TextView points;
		private TextView gamesPlayed;
		private TextView wins;
		private TextView drawns;
		private TextView losses;
		private TextView goalScore;
		
		
	}
	

	public GroupListAdapter(Context context, Group group){
		this.group = group;
		mInflater = LayoutInflater.from(context);
		mContext = context;
	}



	@Override
	public int getCount() {
		return 5;
	}




	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return null;
	}




	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.group_score_layout, null);
			holder = new ViewHolder();  
			holder.teamFlag = (ImageView) convertView.findViewById(R.id.imageViewTeamFlag);
			holder.points = (TextView) convertView.findViewById(R.id.textViewPoints);
			holder.gamesPlayed = (TextView) convertView.findViewById(R.id.TextViewGames);
			holder.wins = (TextView) convertView.findViewById(R.id.TextViewWins);
			holder.drawns = (TextView) convertView.findViewById(R.id.TextViewDrawn);
			holder.losses = (TextView) convertView.findViewById(R.id.TextViewLoss);
			holder.goalScore = (TextView) convertView.findViewById(R.id.TextViewGoalScore);
			holder.teamName = (TextView) convertView.findViewById(R.id.textViewTeamName);
			
            convertView.setTag(holder);
                  
			
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		Resources r = mContext.getResources();	
		if(position==0){
			holder.teamFlag.setImageResource(android.R.color.transparent);

			holder.teamName.setText("");
			holder.points.setText(r.getString(R.string.pointsAbreviation));
			holder.drawns.setText(r.getString(R.string.drawnAbreviation));
			holder.gamesPlayed.setText(r.getString(R.string.gamesPlayedAbreviation));
			holder.wins.setText(r.getString(R.string.winsAbreviation));
			holder.losses.setText(r.getString(R.string.lossAbreviation));
			holder.goalScore.setText(r.getString(R.string.goalScoreAbreviation));
		} else {
			
		
		Team team = group.getTeams().get(position + EXTRA);
		
		holder.teamFlag.setImageResource(r.getIdentifier(team.getFlag(), "drawable",  mContext.getPackageName()));
		holder.teamName.setText(team.getLocalizedName());
		holder.points.setText(String.valueOf(team.getPoints()));
		holder.drawns.setText(String.valueOf(team.getDrawn()));
		holder.gamesPlayed.setText(String.valueOf(team.getGamesPlayed()));
		holder.wins.setText(String.valueOf(team.getWins()));
		holder.losses.setText(String.valueOf(team.getLosses()));
		holder.goalScore.setText(String.valueOf(team.getGoalScore()));
		
		}
		return convertView;
	}

}
